package com.personal.o2o.util;

import com.google.code.kaptcha.Constants;

import javax.servlet.http.HttpServletRequest;

public class CodeUtil {

    /**
     * 验证验证码是否为空或者不相等
     * @param request
     * @return
     */
    public static boolean checkVerifyCode(HttpServletRequest request){
        // 实际的验证码
        String verifyCodeExpected = (String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
        // 用户输入的验证码
        String verifyCodeActual = HttpServletRequestUtil.getString(request,"verifyCodeActual");
        if (verifyCodeActual == null||!verifyCodeExpected.equals(verifyCodeActual)){
            return false;
        }
        return true;
    }
}
